package com.ddn.service.hall.impl;

import com.ddn.mapper.hall.DiningMapper;
import com.ddn.model.hall.Dining;
import com.ddn.service.hall.DiningService;
import com.ddn.util.ResultData;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/*
  ❀❀❀---扎根---❀❀❀
    ❤ @libing ❤
  
*/
@Service
public class DiningServiceImpl implements DiningService {

    @Autowired
    private DiningMapper diningMapper;

    /**
     * 查找全部就餐信息
     * @param map
     * @return
     */
    @Override
    public ResultData findAllDining(HashMap<String, Object> map) {
        String pageNo = (String) map.get("page");
        String pageSize = (String) map.get("limit");
        PageHelper.startPage(Integer.parseInt(pageNo),Integer.parseInt(pageSize));

        List<Dining> diningList= diningMapper.findAllDining(map);

        PageInfo<Dining> info =new PageInfo<>(diningList);

        long l = info.getTotal();
        if (diningList != null) {
            return ResultData.ok(diningList,l);
        }
        return ResultData.fail();
    }

    /**
     * 删除餐厅就餐信息
     * @param map
     * @return
     */
    @Override
    public ResultData deleteDining(HashMap<String, Object> map) {
        int i =diningMapper.deleteDining(map);
        if (i >0) {
            return ResultData.ok();
        }
        return ResultData.fail();
    }

    /**
     * 添加餐厅就餐信息
     * @param map
     * @return
     */
    @Override
    public ResultData addDining(HashMap<String, Object> map) {
        int i =diningMapper.addDining(map);
        if (i >0) {
            return ResultData.ok();
        }
        return ResultData.fail();
    }

    /**
     * 更新餐厅信息
     * @param map
     * @return
     */
    @Override
    public ResultData updateDining(HashMap<String, Object> map) {
        int i =diningMapper.updateDining(map);
        if (i >0) {
            return ResultData.ok();
        }
        return ResultData.fail();
    }

    /**
     * 批量删除餐厅信息
     * @param ids
     * @return
     */
    @Override
    public ResultData batchDining(List<Integer> ids) {
        int i =diningMapper.batchDining(ids);
        if (i >0) {
            return ResultData.ok();
        }
        return ResultData.fail();
    }
}
